package com.relife.core.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "sys_code", uniqueConstraints = { @UniqueConstraint(columnNames = { "CODE" }) })
public class CodeEntity extends BaseEntity {

	private static final long serialVersionUID = 1L;
	private String name;
	private String code;
	private String value;
	private String val;
	private Integer orderBy;
	private List<CodeEntity> children;
	private CodeEntity parent;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy(value = "orderBy ASC")
	public List<CodeEntity> getChildren() {
		return children;
	}

	public void setChildren(List<CodeEntity> children) {
		this.children = children;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	public CodeEntity getParent() {
		return parent;
	}

	public void setParent(CodeEntity parent) {
		this.parent = parent;
	}

	public Integer getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(Integer orderBy) {
		this.orderBy = orderBy;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getVal() {
		return val;
	}

	public void setVal(String val) {
		this.val = val;
	}
}
